package per.wsj.room.ui.main

import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import kotlinx.coroutines.launch
import per.wsj.room.data.UserRepository
import per.wsj.room.data.entity.User

class MainViewModel : ViewModel() {

    var mRepository: UserRepository? = null

    init{
        if (mRepository == null) {
            mRepository = UserRepository.getInstance()
        }
    }

    fun getUsers(): LiveData<List<User>> {
        return mRepository?.getUsers()!!
    }

//    fun addUser(user: User) = viewModelScope.launch {
//        mRepository?.addUser2(user)
//    }

    fun addUser2(user: User) {
        mRepository?.addUser2(user)
    }
}
